package com.ce.server.common;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @DATE: 2021/11/19 09:13
 * @Author: 小爽帅到拖网速
 */
@RestControllerAdvice
public class GlobalException {

  @ExceptionHandler(SQLException.class)
  public RespBean mySqlException(SQLException e){
    // sql违反了完整性约束异常
    if (e instanceof SQLIntegrityConstraintViolationException){
      return RespBean.error("该数据有关联数据，操作失败！");
    }
    return RespBean.error("数据库异常，操作失败！");
  }
}